package icu.guodapeng.oauth2.service.impl

import icu.guodapeng.oauth2.domain.user.enum.RedisConstant
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.stereotype.Service
import java.util.*
import javax.annotation.PostConstruct
import javax.annotation.Resource


/**
 * 资源与角色匹配关系管理业务类
 */
@Service
class ResourceServiceImpl {

    @Resource
    lateinit var redisTemplate: RedisTemplate<String, Any>

    @PostConstruct
    fun initData() {
        val resourceRolesMap: TreeMap<String, List<String>> = TreeMap()
        resourceRolesMap["/api-website/hello"] = listOf("ADMIN")
        resourceRolesMap["/api-website/echo/*"] = listOf("ADMIN")
        resourceRolesMap["/api-work/echo/*"] = listOf("ADMIN")
        resourceRolesMap["/api-website/user/currentUser"] = listOf("USER", "ADMIN")
        redisTemplate.opsForHash<String, List<String>>()
            .putAll(RedisConstant.RESOURCE_ROLES_MAP.value, resourceRolesMap)
    }
}
